#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QDebug>
#include <QFileDialog>
#include <QPushButton>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    OpenFile();
    SaveFile();
}

void MainWindow::OpenFile()
{
    QPushButton* btn = new QPushButton("打开文件", this);
    QFileDialog* fdg = new QFileDialog(this);

    connect(btn, &QPushButton::clicked, [=](){
        // 返回值为选中的文件的路径，可以用于后续操作
        QString str = fdg->getOpenFileName(this,
                                           "open file",
                                           "F:/1.Code_Library/QtCode/QFileDialog",
                                           "*.h");

        qDebug() << str;
    });
}

void MainWindow::SaveFile()
{
    QPushButton* btn = new QPushButton("保存文件", this);
    btn->move(200,0);
    QFileDialog* fdg = new QFileDialog(this);

    connect(btn, &QPushButton::clicked, [=](){
        // 返回值为选中的文件的路径，可以用于后续操作
        QString str = fdg->getSaveFileName(this,
                             "save file",
                             "F:/1.Code_Library/QtCode/QFileDialog",
                             "*.txt");
        qDebug() << str;
    });
}


MainWindow::~MainWindow()
{
    delete ui;
}

